﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Contracts;
using System.Threading;
using System.IO;

namespace Radar {
    public class Sensor {
        private readonly IRepository _rep = Repository.GetInstance();
        private readonly Timer t;
        private readonly int _maxSpeed;
        private int _currFileIdx;

        public Sensor(int maxSpeed) {
            t = new Timer(DoWork, _rep, 5000, 5000);
            _maxSpeed = maxSpeed;
        }

        private void DoWork(Object o) {
            String filename = Directory.GetFiles(@"C:\Users\Ricardo Neto\Pictures\Wallpapers")[_currFileIdx++];
            FileStream s = new FileStream(filename, FileMode.Open, FileAccess.Read);
            byte[] image = new byte[s.Length];
            s.Read(image, 0, (int)s.Length);
            ((IRepository)_rep).AddEvent(new Event(3.5f, image, filename));                    
        }

    }
}
